package com.tx.websocket.demo.shiro;


import com.tx.websocket.demo.redis.CommonConfig;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RedisCacheManager implements CacheManager {

    @Resource
    private RedisTemplate redisTemplate;

    @Resource
    private CommonConfig config;

    @Override
    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
        return new ShiroCache<>(name, redisTemplate, config);
    }

}
